/*
	This file is part of AVRCppLib.

    AVRCppLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AVRCppLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AVRCppLib.  If not, see <http://www.gnu.org/licenses/>.

    Copyright (C) Maxime Lemonnier 2007-2011
 */

#ifndef ADCHardware_H_
#define ADCHardware_H_

#include "../Utils/CppExtensions.h"
#include "../Utils/BitManipulation.h"
#include "Compatibility/ADCHardwareCompatibilityInterface.h"
#include "../CallbackServers/CallbackConnector.h"
#include "Prescalers.h"
#include "ChannelModes.h"
#include "VoltageReferences.h"

namespace ADCs
{




using Prescalers::Prescaler;
using ChannelModes::ChannelMode;
using VoltageReferences::VoltageReference;

/*! Analog to digital conversion class.
 */
class ADCHardware : public CallbackConnector
{
public:



	static ADCHardware* getInstance();

	inline void enableADC() FORCE_INLINE;

	inline void disableADC() FORCE_INLINE;

	inline void enableAutoTriggering() FORCE_INLINE;

	inline void disableAutoTriggering() FORCE_INLINE;

	inline void enableInterrupts() FORCE_INLINE;

	inline void disableInterrupts() FORCE_INLINE;

	inline bool isConversionComplete() FORCE_INLINE;

	inline void clearConversionCompleteFlag() FORCE_INLINE;

	inline uint16_t read() FORCE_INLINE;

	inline bool isBusy() FORCE_INLINE;

	inline void startConverter() FORCE_INLINE;

	inline void setPrescaler(Prescaler prescaler) FORCE_INLINE;

	inline void setVoltageReference(VoltageReference voltageReference) FORCE_INLINE;

	inline void setChannelMode(ChannelMode channelMode) FORCE_INLINE;

	inline void leftAdjust()  FORCE_INLINE;

	inline void rightAdjust()  FORCE_INLINE;

protected:

	IOAddress adcsra;
	IOAddress admux;
	IOAddress sfior;
	IOAddress16 adc;

	IOAddress triggers;
	uint8_t triggersMask;

	/*! Private Constructor.
	 * This class is a Singleton, access it via \a getInstance()
	 */
	ADCHardware(uint8_t callbackVectorNumber, IOAddress acdsra, IOAddress admux, IOAddress16 adc);

};

#include "ADCHardware-definitions.h"

}

#endif /*ADCHardware_H_*/
